<template>
  <div class="container">
    <el-form :model="formList" ref="formList" :rules="rules" label-width="80px" :inline="false" size="normal">
      <el-form-item label="角色名称">
        <el-input v-model="formList.name"></el-input>
      </el-form-item>
      <el-form-item label="英文名称">
        <el-input v-model="formList.enname"></el-input>
      </el-form-item>
      <el-form-item label="系统数据">
        <el-radio-group v-model="formList.is_sys" size="normal">
          <el-radio-button label="1">是</el-radio-button>
          <el-radio-button label="0">否</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否可用">
        <el-radio-group v-model="formList.useable" size="normal">
          <el-radio-button label="1">是</el-radio-button>
          <el-radio-button label="0">否</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="数据范围">
        <el-select v-model="formList.data_scope" value-key="data_scope" clearable class="wid">
          <el-option value="1" label="所有数据"></el-option>
          <el-option value="2" label="所在公司及以下数据"></el-option>
          <el-option value="3" label="所在公司数据"></el-option>
          <el-option value="4" label="所在部门及以下数据"></el-option>
          <el-option value="5" label="所在部门数据"></el-option>
          <el-option value="8" label="仅本人数据"></el-option>
          <el-option value="9" label="按明细设置"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="生效范围">
        <el-row :gutter="20">
          <el-col :span="10" :offset="0">
            <el-select v-model="formList.auth_start" class="wid">
              <el-option value="1" label="1"></el-option>
              <el-option value="2" label="2"></el-option>
              <el-option value="3" label="3"></el-option>
              <el-option value="4" label="4"></el-option>
              <el-option value="5" label="5"></el-option>
              <el-option value="6" label="6"></el-option>
              <el-option value="7" label="7"></el-option>
              <el-option value="8" label="8"></el-option>
              <el-option value="9" label="9"></el-option>
              <el-option value="99" label="MAX"></el-option>
            </el-select>
          </el-col>
          <el-col :span="10" :offset="0">
            <el-select v-model="formList.auth_end" class="wid">
              <el-option value="1" label="1"></el-option>
              <el-option value="2" label="2"></el-option>
              <el-option value="3" label="3"></el-option>
              <el-option value="4" label="4"></el-option>
              <el-option value="5" label="5"></el-option>
              <el-option value="6" label="6"></el-option>
              <el-option value="7" label="7"></el-option>
              <el-option value="8" label="8"></el-option>
              <el-option value="9" label="9"></el-option>
              <el-option value="99" label="MAX"></el-option>
            </el-select>
          </el-col>
          <el-col :span="2" :offset="0">
            <el-button type="warning" icon="el-icon-more-outline" circle @click="tishi"></el-button>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="formList.remarks" type="textarea" :rows="4"></el-input>
      </el-form-item>
    </el-form>
    <div class="center">
      <el-button type="danger" size="default" @click="cancel">取消</el-button>
      <el-button type="primary" size="default" @click="save" :loading="loading">保存</el-button>
    </div>
  </div>
</template>
<script>
export default {
  name: '',
  components: {
  },
  props: {
    infoParams: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      loading: false,
      formList: {
        is_sys: '1',
        useable: '1',
        data_scope: '3',
        auth_start: '1',
        auth_end: '99'
      },
      rules: {}
    }
  },
  created () {

  },
  mounted () {
    if (this.infoParams.id) {
      this.init()
    }
  },
  methods: {
    async init () {
      console.log(this.infoParams);
      const res = await this.$http('sysRoleObj', {
        id: this.infoParams.id
      })
      this.formList = res
    },
    cancel () {
      this.$emit('cancel');
    },
    async save () {
      this.loading = true
      const res = await this.$http('sysRoleUp', {
        ...this.formList
      })
      this.$tips.success(res.errmsg)
      this.loading = false
      this.cancel()
    },
    tishi () {
      this.$tips.warning('给用户建立的角色默认应该选择所在公司数据，让用户只能看到自己和自己之下的机构内容')
    }
  },
  computed: {

  },
  watch: {
    'infoParams.id' (val) {
      if (val) {
        this.init()
      }
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
